
#include "stdafx.h"
#include "CombatState_Forbidden.h"
#include "Combat/EvtCombat.h"
#include "Event/EvtImp.h"
#include "Combat/CombatSysImp.h"
#include "Entity/EntityIf.h"



CombatState_Forbidden::CombatState_Forbidden(void)

{
}

CombatState_Forbidden::~CombatState_Forbidden()
{
}

void
CombatState_Forbidden::enter()
{
	//
	//	m_nTTL==0, unit will keep in current status forever until other change its status
	//	m_nTTL>0, ICombatSys will automatically change current state to ready.
	//

	m_nTTL = 0; //	Forbidden forever
}

void
CombatState_Forbidden::leave()
{

}


bool 
CombatState_Forbidden::update(int nElapse)
{
	if (m_nTTL!=0)
	{
		m_nTTL-=nElapse;
		if (m_nTTL<=0)
		{
			m_wpCombat->setState(Combat::CBS_Ready);
			m_nTTL = 0;
		}
	}
	return true;
}



void 
CombatState_Forbidden::onEvent(IEvt& evt)
{
	if (evt.getID()==EVT_CastStart)
	{
		LOG_ERROR_V("Failed to cast start in : %d !\n", m_wpCombat->getStateName());
	}
	else if (evt.getID()==EVT_CastEnd)
	{
		LOG_ERROR_V("Failed to cast end in : %d !\n", m_wpCombat->getStateName());
	}
	else if (evt.getID()==EVT_CastPrep)
	{
		evt.setDataY(CombatResult::Forbidden);
	}
	else if (evt.getID()==EVT_CastResult)
	{
		m_wpCombat->onEvent_CastResult(evt);
	}
	else if (evt.getID()==EVT_TargetSelected)
	{
		m_wpCombat->onEvent_Target(evt);
	}
}


